#include <iostream>
#include "catch_amalgamated.hpp"

#include <vector>
#include <algorithm>
#include <string>

void stl_vector_test()
{
    std::vector<int> v;
    v.push_back(1);
    v.push_back(2);
    std::for_each(v.begin(), v.end(), [](int &i)
                  { std::cout << i++ << "\n"; });
    std::vector<int>::iterator it = v.begin();
    while (it != v.end())
    {
        std::cout << *it << "\n";
        it++;
    }
}

void replaceAll(std::string &s, const char *o, const char *d)
{
    for (;;)
    {
        std::string::size_type pos = s.find_first_of(o);
        if (pos == std::string::npos) {
            break;
        }
        s.replace(pos, ::strlen(o), d);
    }
}

#include <string>
void stl_string_test()
{
    std::string s = "111-222-333-444-111";
    replaceAll(s, "111", "5555");
    std::cout << s.c_str() << "\n";
    std::string::size_type pos = s.find("222");
    s.replace(pos, 3, "lllll");
    std::cout << s.c_str() << "\n";
    s.erase(pos, -1);
    std::cout << s.c_str() << "\n";
    s.insert(pos, "222-");
    std::cout << s.c_str() << "\n";
    std::string s1 = s.substr(pos, 3);
    std::cout << s1.c_str() << "\n";


    std::string str = ",";
    auto pos0 = str.find_first_of(',');
    char id[64];
    strcpy(id, std::string(str.c_str(), pos0).c_str());
    std::cout << id << "\t->" << std::string(str.c_str(), pos0).c_str() << "\t->" << std::string(str.c_str() + pos0+1).c_str() << "\n";
}

int main(int argc, char const *argv[])
{
    char buf[16] = {0};
    const char* ptr = strstr("ME4002V3-ALG-P23022801.1349.alg", buf);
    printf("%s %d\n", ptr, ptr == NULL);
    // stl_vector_test();
    stl_string_test();
    return 0;
}
